import { aggregationService } from '@/api/aggregation'

// 总公司商家审核相关API

/**
 * 分页查询商家审核
 * @param {Object} params 查询参数
 * @returns {Promise}
 */
export function getMerchantAuditPage(params) {
  return aggregationService({
    url: '/agg/merchantAudit/page',
    method: 'post',
    data: params
  })
}

/**
 * 审核商家
 * @param {Object} data 审核数据
 * @returns {Promise}
 */
export function checkMerchantAudit(data) {
  return aggregationService({
    url: '/agg/merchantAudit/check',
    method: 'post',
    data: data
  })
}

/**
 * 查看商家审核详情
 * @param {number} id 审核ID
 * @returns {Promise}
 */
export function getMerchantAuditDetail(id) {
  return aggregationService({
    url: '/agg/merchantAudit/getInfo',
    method: 'get',
    params: { id }
  })
}

/**
 * 添加商家审核
 * @param {Object} data 商家审核数据
 * @returns {Promise}
 */
export function addMerchantAudit(data) {
  return aggregationService({
    url: '/agg/merchantAudit/add',
    method: 'post',
    data: data
  })
}

/**
 * 编辑商家审核
 * @param {Object} data 商家审核数据
 * @returns {Promise}
 */
export function editMerchantAudit(data) {
  return aggregationService({
    url: '/agg/merchantAudit/edit',
    method: 'post',
    data: data
  })
}

/**
 * 上传文件
 * @param {FormData} formData 文件数据
 * @returns {Promise}
 */
export function uploadFile(formData) {
  return aggregationService({
    url: '/agg/file/upload',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    // 确保文件上传时不被拦截器覆盖Content-Type
    transformRequest: [function (data, headers) {
      // 对于FormData，让浏览器自动设置Content-Type
      if (data instanceof FormData) {
        delete headers['Content-Type']
      }
      return data
    }]
  })
}
